home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWTIsvDlist.z / RWTIsvDlist
Encoding:
Text File  |  1998-10-30  |  14.6 KB  |  463 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTIsvDlist<T> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tidlist.h>
  13.  
  14.  
  15.  
  16.               RWTIsvDlist<T> list;
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttoooonnnn
  22.      Class RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt<<<<TTTT>>>> is a class that implements intrusive doubly-linked
  23.      lists. An intrusive list is one where the member of the list must inherit
  24.      from a common base class, in this case RRRRWWWWIIIIssssvvvvDDDDlllliiiinnnnkkkk.  The advantage of such
  25.      a list is that memory and space requirements are kept to a minimum.  The
  26.      disadvantage is that the inheritance hierarchy is inflexible, making it
  27.      slightly more difficult to use with an existing class.  Class
  28.      RRRRWWWWTTTTVVVVaaaallllDDDDlllliiiisssstttt<<<<TTTT>>>> is offered as an alternative, non-intrusive, linked list.
  29.      See Stroustrup (1991; Section 8.3.1) for more information about intrusive
  30.      lists.  NNNNooootttteeee tttthhhhaaaatttt wwwwhhhheeeennnn yyyyoooouuuu iiiinnnnsssseeeerrrrtttt aaaannnn iiiitttteeeemmmm iiiinnnnttttoooo aaaannnn iiiinnnnttttrrrruuuussssiiiivvvveeee lllliiiisssstttt,,,, tttthhhheeee
  31.      aaaaccccttttuuuuaaaallll iiiitttteeeemmmm (not a copy) is inserted.  Because each item carries only one
  32.      link field, the same item cannot be inserted into more than one list, nor
  33.      can it be inserted into the same list more than once.
  34.  
  35.  
  36. EEEExxxxaaaammmmpppplllleeee
  37.               #include <rw/tidlist.h>
  38.           #include <rw/rstream.h>
  39.           #include <string.h>
  40.  
  41.  
  42.               struct Symbol : public RWIsvDlink {
  43.  
  44.  
  45.  
  46.                 char name[10];
  47.             Symbol( const char* cs)  {
  48.               strncpy(name, cs, sizeof(name)); name[9] = ' ';
  49.             }
  50.           };
  51.  
  52.  
  53.               void printem(Symbol* s, void*) { cout << s->name << endl; }
  54.           main()  {
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.                 RWTIsvDlist<Symbol> list;
  75.             list.insert( new Symbol("one") );
  76.             list.insert( new Symbol("two") );
  77.             list.prepend( new Symbol("zero") );
  78.  
  79.  
  80.                 list.apply(printem, 0);
  81.  
  82.  
  83.  
  84.                 list.clearAndDestroy();  // Deletes the items inserted into
  85.                                      // the list
  86.             return 0;
  87.           }
  88.  
  89.  
  90.      PPPPrrrrooooggggrrrraaaammmm OOOOuuuuttttppppuuuutttt::::
  91.  
  92.               zero
  93.           one
  94.  
  95. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  96.      two
  97.  
  98.  
  99.  
  100.               RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt();
  101.  
  102.  
  103.      Constructs an empty list.
  104.  
  105.               RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt(T* a);
  106.  
  107.  
  108.      Constructs a list with the single item pointed to by aaaa in it.
  109.  
  110. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  111.               void
  112.           aaaappppppppeeeennnndddd(T* a);
  113.  
  114.  
  115.      Appends the item pointed to by aaaa to the end of the list.
  116.  
  117.               void
  118.           aaaappppppppllllyyyy(void (*applyFun)(T*, void*), void* d);
  119.  
  120.  
  121.      Calls the function pointed to by aaaappppppppllllyyyyFFFFuuuunnnn to every item in the
  122.      collection.  This must have the prototype:
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               void  yyyyoooouuuurrrrFFFFuuuunnnn(T* item, void* d);
  141.  
  142.  
  143.  
  144.  
  145.  
  146.      The item will be passed in as argument iiiitttteeeemmmm.  Client data may be passed
  147.      through as parameter dddd.
  148.  
  149.               T*
  150.           aaaatttt(size_t i) const;
  151.  
  152.  
  153.      Returns the item at index iiii.  The index iiii must be between zero and the
  154.      number of items in the collection less one, or an exception of type
  155.      TTTTOOOOOOOOLLLL____IIIINNNNDDDDEEEEXXXX will be thrown.
  156.  
  157.               void
  158.           cccclllleeeeaaaarrrr();
  159.  
  160.  
  161.      Removes all items from the list.
  162.  
  163.               void
  164.           cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy();
  165.  
  166.  
  167.      Removes aaaannnndddd ccccaaaallllllllssss ddddeeeelllleeeetttteeee for each item in the list.  Note that this
  168.      assumes that each item was allocated off the heap.
  169.  
  170.               RWBoolean
  171.           ccccoooonnnnttttaaaaiiiinnnnssss(RWBoolean (*testFun)(const T*, void*),void* d)
  172.                    const;
  173.  
  174.  
  175.      Returns TTTTRRRRUUUUEEEE if the list contains an item for which the user-defined
  176.      "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE .  The tester
  177.      function must have the prototype:
  178.  
  179.               RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  180.  
  181.  
  182.  
  183.  
  184.  
  185.      For each item in the list this function will be called with the item as
  186.      the first argument.  Client data may be passed through as parameter dddd.
  187.  
  188.               RWBoolean
  189.           ccccoooonnnnttttaaaaiiiinnnnssssRRRReeeeffffeeeerrrreeeennnncccceeee(const T* a) const;
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      Returns TTTTRRRRUUUUEEEE if the list contains an item with the address aaaa.
  207.  
  208.               size_t
  209.           eeeennnnttttrrrriiiieeeessss() const;
  210.  
  211.  
  212.      Returns the number of items currently in the list.
  213.  
  214.               T*
  215.           ffffiiiinnnndddd(RWBoolean (*testFun)(const T*, void*),void* d) const;
  216.  
  217.  
  218.      Returns the first item in the list for which the user-defined "tester"
  219.      function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE.  If there is no such item,
  220.      then returns nnnniiiillll.  The tester function must have the prototype:
  221.  
  222.                  RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  223.  
  224.  
  225.  
  226.  
  227.  
  228.      For each item in the list this function will be called with the item as
  229.      the first argument.  Client data may be passed through as parameter dddd.
  230.  
  231.               T*
  232.           ffffiiiirrrrsssstttt() const;
  233.  
  234.  
  235.      Returns (but does not remove) the first item in the list, or nnnniiiillll if the
  236.      list is empty.
  237.  
  238.               T*
  239.           ggggeeeetttt();
  240.  
  241.  
  242.      Returns aaaannnndddd rrrreeeemmmmoooovvvveeeessss the first item in the list, or nnnniiiillll if the list is
  243.      empty.
  244.  
  245.               size_t
  246.           iiiinnnnddddeeeexxxx(RWBoolean (*testFun)(const T*, void*),void* d) const;
  247.  
  248.  
  249.      Returns the index of the first item in the list for which the user-
  250.      defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE.  If there
  251.      is no such item, then returns RRRRWWWW____NNNNPPPPOOOOSSSS.  The tester function must have the
  252.      prototype:
  253.  
  254.                  RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.  
  273.  
  274.      For each item in the list this function will be called with the item as
  275.      the first argument.  Client data may be passed through as parameter dddd.
  276.  
  277.               void
  278.           iiiinnnnsssseeeerrrrtttt(T* a);
  279.  
  280.  
  281.      Appends the item pointed to by aaaa to the end of the list.  This item
  282.      cannot be inserted into more than one list, nor can it be inserted into
  283.      the same list more than once.
  284.  
  285.               void
  286.           iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, T* a);
  287.  
  288.  
  289.      Insert the item pointed to by aaaa at the index position iiii.  This position
  290.      must be between zero and the number of items in the list, or an exception
  291.      of type TTTTOOOOOOOOLLLL____IIIINNNNDDDDEEEEXXXX will be thrown.  The item cannot be inserted into more
  292.      than one list, nor can it be inserted into the same list more than once.
  293.  
  294.               RWBoolean
  295.           iiiissssEEEEmmmmppppttttyyyy() const;
  296.  
  297.  
  298.      Returns TTTTRRRRUUUUEEEE if there are no items in the list, FFFFAAAALLLLSSSSEEEE otherwise.
  299.  
  300.               T*
  301.           llllaaaasssstttt() const;
  302.  
  303.  
  304.      Returns (but does not remove) the last item in the list, or nnnniiiillll if the
  305.      list is empty.
  306.  
  307.               size_t
  308.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(RWBoolean (*testFun)(const T*, void*),void* d)
  309.                         const;
  310.  
  311.  
  312.      Traverses the list and returns the number of times for which the user-
  313.      defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returned TTTTRRRRUUUUEEEE .  The
  314.      tester function must have the prototype:
  315.  
  316.                  RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  317.  
  318.  
  319.  
  320.  
  321.  
  322.      For each item in the list this function will be called with the item as
  323.      the first argument.  Client data may be passed through as parameter dddd
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               size_t
  339.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffffRRRReeeeffffeeeerrrreeeennnncccceeee(const T* a) const;
  340.  
  341.  
  342.      Returns the number of times which the item pointed to by aaaa occurs in the
  343.      list.  Because items cannot be inserted into a list more than once, this
  344.      function can only return zero or one.
  345.  
  346.               void
  347.           pppprrrreeeeppppeeeennnndddd(T* a);
  348.  
  349.  
  350.      Prepends the item pointed to by aaaa to the beginning of the list.
  351.  
  352.               T*
  353.           rrrreeeemmmmoooovvvveeee(RWBoolean (*testFun)(const T*, void*),void* d);
  354.  
  355.  
  356.      Removes and returns the first item for which the user-defined tester
  357.      function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or nnnniiiillll if there is no such
  358.      item.  The tester function must have the prototype:
  359.  
  360.                  RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(const T* item, void* d);
  361.  
  362.  
  363.  
  364.  
  365.  
  366.      For each item in the list this function will be called with the item as
  367.      the first argument.  Client data may be passed through as parameter dddd.
  368.  
  369.               T*
  370.           rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i);
  371.  
  372.  
  373.      Removes and returns the item at index iiii.  The index iiii must be between
  374.      zero and the number of items in the collection less one or an exception
  375.      of type TTTTOOOOOOOOLLLL____IIIINNNNDDDDEEEEXXXX will be thrown.
  376.  
  377.               T*
  378.           rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt();
  379.  
  380.  
  381.      Removes and returns the first item in the list, or nnnniiiillll if there are no
  382.      items in the list.
  383.  
  384.               T*
  385.           rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt();
  386.  
  387.  
  388.      Removes and returns the last item in the list, or nnnniiiillll if there are no
  389.      items in the list.
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))                                            RRRRWWWWTTTTIIIIssssvvvvDDDDlllliiiisssstttt((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.               T*
  405.           rrrreeeemmmmoooovvvveeeeRRRReeeeffffeeeerrrreeeennnncccceeee(T* a);
  406.  
  407.  
  408.      Removes and returns the item with address aaaa, or nnnniiiillll if there is no such
  409.      item.
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.